<template>
	<view>
		<view class="u-flex user-box u-p-t-30 u-p-l-30 u-p-r-20 u-p-b-30">
			<view class="u-m-r-10 avator-item">
				<oss-upload></oss-upload>
			</view>
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20">{{vuex_user.name}}</view>
				<view class="u-font-14 u-tips-color">邮箱:{{vuex_user.email}}</view>
			</view>
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="setting" title="个人中心" @tap="toBaseInfo"></u-cell-item>
			</u-cell-group>
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="rmb-circle" title="订单中心" @tap="toOrder"></u-cell-item>
				<u-cell-item icon="star" title="我的收藏" @tap="toCollect"></u-cell-item>
				<u-cell-item icon="map" title="地址管理" @tap="toAdress"></u-cell-item>
			</u-cell-group>
		</view>
		
		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell-item icon="reload" title="注销登陆" @tap="logout"></u-cell-item>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pic:'https://uviewui.com/common/logo.png',
				show:true
			}
		},
		onLoad() {
			// 判断是否登陆
			if(!this.$u.utils.isLogin()) return;
		},
		methods: {
			toBaseInfo() {
				this.$u.route({
					type: 'navigateTo',
					url: 'pages/center/baseInfo'
				});
			},
			toAdress() {
				this.$u.route({
					type: 'navigateTo',
					url: 'pages/address/address'
				});
			},
			toOrder() {
				this.$u.route({
					type: 'navigateTo',
					url: 'pages/order/order'
				});
			},
			toCollect() {
				this.$u.route({
					type: 'navigateTo',
					url: 'pages/collects/collects'
				});
			},
			async logout() {
				// 请求API退出后台服务
				await this.$u.api.authLogout()
				this.$u.toast('退出成功')
				
				setTimeout(() => {
					// 清空缓存
					this.$u.vuex('vuex_user', {});
					this.$u.vuex('vuex_token', null);
					// 跳转到首页
					this.$u.route({
						type: 'reLaunch',
						url: 'pages/index/index'
					})
				}, 1500)
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #ededed;
}

.camera{
	width: 54px;
	height: 44px;
	
	&:active{
		background-color: #ededed;
	}
}
.user-box{
	background-color: #fff;
}
.avator-item {
	height: 70px;
	width: 70px;
}
</style>